package com.xxx.video.dynamic.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.dynamic.beans.PersonInfoBean;

import butterknife.BindView;

public class PersonInfoUserInfoAdapter extends BaseRecycleViewAdapter<Object, PersonInfoUserInfoAdapter.MyHolder> {

    private PersonInfoBean successOb;

    public PersonInfoUserInfoAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_person_info;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public void setPersonData(PersonInfoBean successOb) {
        this.successOb = successOb;
        notifyDataSetChanged();

    }

    @Override
    public boolean isSetBaseItemViewClickListener() {
        return false;
    }

    public void addFriendSuccess() {
        successOb.isFriends = 2;
        notifyDataSetChanged();
    }

    class MyHolder extends BaseViewHolder {
        @BindView(R.id.iv_item_person_info_avatar)
        ImageView ivItemPersonInfoAvatar;
        @BindView(R.id.tv_item_person_info_name)
        TextView tvItemPersonInfoName;
        @BindView(R.id.tv_item_person_info_nickname)
        TextView tvItemPersonInfoNickname;
        @BindView(R.id.tv_item_person_info_status)
        TextView tvItemPersonInfoStatus;
        @BindView(R.id.tv_item_person_info_chat)
        TextView tvItemPersonInfoChat;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            PersonInfoBean.UserBean userBean = successOb.user;
            /*
             * avatar
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(userBean.picUrl))
                    .apply(new RequestOptions().circleCrop()
                            .placeholder(R.drawable.icon_default_avatar)
                            .error(R.drawable.icon_default_avatar)
                    ).into(ivItemPersonInfoAvatar);
            /*
             * name
             */
            tvItemPersonInfoName.setText(StringUtils.getInstance().getNotEmptyMsg(userBean.username));
            /*
             * nick name
             */
            tvItemPersonInfoNickname.setText(StringUtils.getInstance().getNotEmptyMsg(userBean.nickName));
            if (successOb.isFriends == 0) {
                tvItemPersonInfoChat.setTextColor(Color.WHITE);
                tvItemPersonInfoChat.setText(StringUtils.getInstance().getString(R.string.tv_item_dynamic_details_person_info_add_friend));
                tvItemPersonInfoChat.setBackgroundResource(R.drawable.bg_item_people_nearby_horizontal_list_add);
            } else if (successOb.isFriends == 1) {
                tvItemPersonInfoChat.setTextColor(ResourcesUtils.getInstance().getColor(R.color.c_333333));
                tvItemPersonInfoChat.setText(StringUtils.getInstance().getString(R.string.item_friend_request_ing));
                tvItemPersonInfoChat.setBackground(null);
            } else if (successOb.isFriends == 2) {
                tvItemPersonInfoChat.setTextColor(Color.WHITE);
                tvItemPersonInfoChat.setBackgroundResource(R.drawable.bg_item_people_nearby_horizontal_list_add);
                tvItemPersonInfoChat.setText(StringUtils.getInstance().getString(R.string.tv_item_dynamic_details_person_info_chat));
            }
            tvItemPersonInfoChat.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(successOb, 0, successOb.isFriends);
                }
            });
        }
    }
}
